#include "voxelrenderer.h"

VoxelRenderer::VoxelRenderer(Chunk* c)
{
    chunk=c;
}

void VoxelRenderer::drawVoxel(float x, float y, float z,voxel& v){
//optimize to vbos later
if(v.drawTop()){
glNormal3f(0,1,0);
glVertex3f( VOXEL_SIZE+x, VOXEL_SIZE+y,-VOXEL_SIZE+z);          // Top Right Of The Quad (Top)
glVertex3f(-VOXEL_SIZE+x, VOXEL_SIZE+y,-VOXEL_SIZE+z);          // Top Left Of The Quad (Top)
glVertex3f(-VOXEL_SIZE+x, VOXEL_SIZE+y, VOXEL_SIZE+z);          // Bottom Left Of The Quad (Top)
glVertex3f( VOXEL_SIZE+x, VOXEL_SIZE+y, VOXEL_SIZE+z);
}

if(v.drawBottom()){
glNormal3f(0,-1,0);
glVertex3f( VOXEL_SIZE+x,-VOXEL_SIZE+y, VOXEL_SIZE+z);          // Top Right Of The Quad (Bottom)
glVertex3f(-VOXEL_SIZE+x,-VOXEL_SIZE+y, VOXEL_SIZE+z);          // Top Left Of The Quad (Bottom)
glVertex3f(-VOXEL_SIZE+x,-VOXEL_SIZE+y,-VOXEL_SIZE+z);          // Bottom Left Of The Quad (Bottom)
glVertex3f( VOXEL_SIZE+x,-VOXEL_SIZE+y,-VOXEL_SIZE+z);
}

if(v.drawFront()){
glNormal3f(0,0,1);
glVertex3f( VOXEL_SIZE+x, VOXEL_SIZE+y, VOXEL_SIZE+z);          // Top Right Of The Quad (Front)
glVertex3f(-VOXEL_SIZE+x, VOXEL_SIZE+y, VOXEL_SIZE+z);          // Top Left Of The Quad (Front)
glVertex3f(-VOXEL_SIZE+x,-VOXEL_SIZE+y, VOXEL_SIZE+z);          // Bottom Left Of The Quad (Front)
glVertex3f( VOXEL_SIZE+x,-VOXEL_SIZE+y, VOXEL_SIZE+z);
}

if(v.drawBack()){
glNormal3f(0,0,-1);
glVertex3f( VOXEL_SIZE+x,-VOXEL_SIZE+y,-VOXEL_SIZE+z);          // Bottom Left Of The Quad (Back)
glVertex3f(-VOXEL_SIZE+x,-VOXEL_SIZE+y,-VOXEL_SIZE+z);          // Bottom Right Of The Quad (Back)
glVertex3f(-VOXEL_SIZE+x, VOXEL_SIZE+y,-VOXEL_SIZE+z);          // Top Right Of The Quad (Back)
glVertex3f( VOXEL_SIZE+x, VOXEL_SIZE+y,-VOXEL_SIZE+z);
}

if(v.drawLeft()){
glNormal3f(-1,0,0);
glVertex3f(-VOXEL_SIZE+x, VOXEL_SIZE+y, VOXEL_SIZE+z);          // Top Right Of The Quad (Left)
glVertex3f(-VOXEL_SIZE+x, VOXEL_SIZE+y,-VOXEL_SIZE+z);          // Top Left Of The Quad (Left)
glVertex3f(-VOXEL_SIZE+x,-VOXEL_SIZE+y,-VOXEL_SIZE+z);          // Bottom Left Of The Quad (Left)
glVertex3f(-VOXEL_SIZE+x,-VOXEL_SIZE+y, VOXEL_SIZE+z);
}

if(v.drawRight()){
glNormal3f(1,0,0);
glVertex3f( VOXEL_SIZE+x, VOXEL_SIZE+y,-VOXEL_SIZE+z);          // Top Right Of The Quad (Right)
glVertex3f( VOXEL_SIZE+x, VOXEL_SIZE+y, VOXEL_SIZE+z);          // Top Left Of The Quad (Right)
glVertex3f( VOXEL_SIZE+x,-VOXEL_SIZE+y, VOXEL_SIZE+z);          // Bottom Left Of The Quad (Right)
glVertex3f( VOXEL_SIZE+x,-VOXEL_SIZE+y,-VOXEL_SIZE+z);
}

}
